﻿using System;
using System.Windows.Forms;
using BLL.MaterialBLL;
using Model;

namespace MDMUI
{
    public partial class CreMaterial : Form
    {
        private BLL.MaterialBLL.MaterialBLL _materialBLL = new BLL.MaterialBLL.MaterialBLL();

        public CreMaterial()
        {
            InitializeComponent();
        }

        private void btnCreate_Click(object sender, EventArgs e)
        {
            // 获取用户输入的物料信息
            string materialType = txtMaterialType.Text;
            string detailedMaterialType = txtDetailedMaterialType.Text;
            int quantity = int.Parse(txtQuantity.Text);
            string materialUnit = txtMaterialUnit.Text;
            string materialDescription = txtMaterialDescription.Text;
            string consumptionDeduction = txtConsumptionDeduction.Text;
            string materialGroupNumber = txtMaterialGroupNumber.Text;

            // 创建物料对象 - 明确指定使用 Model.Material
            Model.Material newMaterial = new Model.Material
            {
                MaterialType = materialType,
                DetailedMaterialType = detailedMaterialType,
                Quantity = quantity,
                MaterialUnit = materialUnit,
                MaterialDescription = materialDescription,
                ConsumptionDeduction = consumptionDeduction,
                MaterialGroupNumber = materialGroupNumber
            };

            // 调用 BLL 层的方法插入数据
            int result = _materialBLL.AddMaterial(newMaterial);

            if (result > 0)
            {
                MessageBox.Show("物料添加成功！");
                this.Close(); // 关闭窗体
            }
            else
            {
                MessageBox.Show("物料添加失败！");
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close(); // 关闭窗体
        }
    }
}